﻿namespace VIT.BusinessLogicLayer
{
    using System.Collections.Generic;
    using System.Linq;

    using VIT.DataAccessLayer;
    using VIT.DataTransferObjects.Presentation;

    public class SupportOnlineBLL : BLLBase
    {
        private readonly ISupportOnlineDAL _supportOnlineDAL;

        #region Constructor

        public SupportOnlineBLL(string connectionString = "")
            : base(connectionString)
        {
            this._supportOnlineDAL = new SupportOnlineDAL(this.DatabaseFactory);
        }
        #endregion

        public IList<SupportOnlineDto> GetByCategory(int categoryId, int companyId, string language)
        {
            var lst = _supportOnlineDAL.GetAllIncludes()
                .Where(o => o.CategoryId == categoryId && o.Item.CompanyId == companyId)
                .Where(o => o.Category.Item.HasDeleted == false && o.Item.IsPublished && !o.Item.HasDeleted)
                .OrderBy(online => online.Item.Orders)
                .Select(o => new SupportOnlineDto
                {
                    Id = o.Id,
                    NickName = o.NickName,
                    FullName = o.FullName,
                    Phone = o.Phone,
                    TypeId = o.TypeId,
                    TypeName = o.SupportOnlineType.Name,
                    GroupId = o.CategoryId,
                    GroupName = o.Category.CategoryLanguages.FirstOrDefault(c => c.LanguageId == language).Title
                });
            return lst.ToList();
        }
    }
}

